<!-- <?php
include_once("./Db_pdo.class.php");


ini_set('date.timezone','Asia/Shanghai');
// $DB=new Db_pdo("jmshop","root","root");
// $DB=new Db_pdo("cxh_v3_test","cxhv3","cxhv3pwd!@#");
$DB=new Db_pdo("cxh_v3","cxhv3","cxhv3pwd!@#");
echo '<pre>';

//门票的流水（单）
$ticket_log = unserialize(file_get_contents('ticket_log.txt')); 
$arr = array_chunk($ticket_log, 20000);
foreach($arr as $v) {
	$sql = "INSERT INTO ims_cxh_apply_subsidy_back (`apb_type`,`bus_id`,`apb_money`,`apb_intgral`,`apb_fee`,`member_id`,`ctime`) VALUES ";
	foreach ($v as $value) { 
		$param['apb_type'] = 3;

		$param['bus_id'] =$value['id'];
		$param['apb_money'] = $value['need_back'];
		$param['apb_intgral'] =0;
		$param['apb_fee'] =0;
		$param['member_id'] = $value['user_id'];
		$param['ctime'] = $value['back_time'];
		// $s.='(null,3,'.$value['id'].','.$value['need_back'].',0,0,'.$value['user_id'].','.$value['back_time'].'),';
		// echo $s;
	    $values="('".implode("','",array_values($param))."'),";
	    // echo $values;
	    $sql .= $values;
	}
	$sql = rtrim($sql, ",");
	$DB->db->query($sql);
	// return ;
}

$arr1 =array_chunk($ticket_log, 10000);
foreach ($arr1 as $v1) {

	$sql1 = "INSERT INTO ims_cxh_cash_log (`cash_bus_type`,`cash_type`,`cash_now`,`cash_old`,`cash_num`,`remark`,`member_id`,`ctime`) VALUES ";
	foreach ($v1 as $value1) {
		$param1['cash_bus_type'] = 3;
		$param1['cash_type'] =1;

		$param1['cash_now'] =$value1['need_back'];
		$param1['cash_old'] = 0;
		$param1['cash_num'] ='+'.$value1['need_back'];
		$param1['remark'] ='[特殊商品每日补贴] '.date('Y-m-d',$value1['back_time']);
		$param1['member_id'] = $value1['user_id'];
		$param1['ctime'] = $value1['back_time'];

		$valuees="('".implode("','",array_values($param1))."'),";
		$sql1 .= $valuees;
	}
	$sql1 = rtrim($sql1, ",");
	// echo $sql;
	$DB->new_query($sql1);
	
}

//车补记录
$data=$DB->table("ims_cxh_apply_subsidy_car")->field('aplc_totel_retime,aplc_re_money,id,aplc_re_fee_p,aplc_totel_money,aplc_totel_days,member_id')->select();
 file_put_contents('car_log.txt',serialize($data));
// print_r($data);
// exit;
$new_arr =array();
foreach ($data as $ke => $va) {
	if($va['aplc_totel_retime']){
		
		$param2['bus_id'] =$va['id'];
		$param2['member_id'] = $va['member_id'];
		if($va['aplc_totel_days']==2000){
			$ratio =0.0005;
		}else if($va['aplc_totel_days']==1667){
			$ratio =0.0006;
		}
		// $ratio = $va['aplc_totel_money']/$va['aplc_totel_days'];
		//金额
		if($va['aplc_re_fee_p']){
			$param2['apb_money'] = $va['aplc_totel_money']*$ratio*0.8;
			$param2['apb_fee'] =$va['aplc_totel_money']*$ratio*0.2;
		}else{
			$param2['apb_money'] = $va['aplc_totel_money']*$ratio;
			$param2['apb_fee'] =0;
		}

		for($i=1;$i<=$va['aplc_totel_retime'];$i++){
			$param2['ctime'] = time()-86400*$i;
			$new_arr[] = $param2;
		}

		
		


	}
}

//集中处理
$arr2 =array_chunk($new_arr, 10000);
foreach($arr2 as $va1) {
	$sql2 = "INSERT INTO ims_cxh_apply_subsidy_back (`apb_type`,`bus_id`,`apb_money`,`apb_intgral`,`apb_fee`,`member_id`,`ctime`) VALUES ";
	foreach ($va1 as $value2) { 
		$condition['apb_type'] = 1;

		$condition['bus_id'] =$value2['bus_id'];
		$condition['apb_money'] = $value2['apb_money'];
		$condition['apb_intgral'] =0;
		$condition['apb_fee'] =$value2['apb_fee'];
		$condition['member_id'] = $value2['member_id'];
		$condition['ctime'] = $value2['ctime'];
		
	    $f_value="('".implode("','",array_values($condition))."'),";
	    // echo $values;
	    $sql2 .= $f_value;
	}
	$sql2 = rtrim($sql2, ",");
	$DB->db->query($sql2);
	// return ;
}







































 -->